package beautiful.butterfly.drds.datasource.connection_contexts.mock;

import beautiful.butterfly.drds.datasource.connection_contexts.api.IConnectionContext;
import beautiful.butterfly.drds.datasource.connection_contexts.api.IRowDataMapList;
import beautiful.butterfly.drds.datasource.connection_contexts.api.ISql;
import beautiful.butterfly.drds.datasource.connection_contexts.spi.RowDataMapList;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Sql implements ISql

{
    private IConnectionContext connectionContext;
    private Statement statement;

    public Sql(IConnectionContext connectionContext, Statement statement) {
        this.connectionContext = connectionContext;
        this.statement = statement;
    }

    public IConnectionContext getConnectionContext() {
        return this.connectionContext;
    }

    public Statement getStatement() {
        return this.statement;
    }

    public void close() throws SQLException {
        this.statement.close();
    }

    public boolean isClosed() throws SQLException {
        return this.statement.isClosed();
    }

    //
    public final void addBatch(String sql) throws SQLException {
        this.statement.addBatch(sql);
    }

    public int[] executeBatch() throws SQLException {
        return this.statement.executeBatch();
    }

    public final void clearBatch() throws SQLException {
        this.statement.clearBatch();
    }

    //
    public final int executeUpdate(String sql) throws SQLException {
        return this.statement.executeUpdate(sql);
    }

    public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
        return this.statement.executeUpdate(sql, autoGeneratedKeys);
    }

    public final int getUpdateCount() throws SQLException {
        return this.statement.getUpdateCount();
    }

    public final IRowDataMapList getGeneratedKeys() throws SQLException {
        ResultSet resultSet = this.statement.getGeneratedKeys();

        IRowDataMapList rowDataMapList = new RowDataMapList(this, resultSet);
        return rowDataMapList;
    }

    //
    public final IRowDataMapList executeQuery(String sql) throws SQLException {
        ResultSet resultSet = this.statement.executeQuery(sql);
        IRowDataMapList rowDataMapList = new RowDataMapList(this, resultSet);

        return rowDataMapList;
    }


    //
    public void setQueryTimeout(int queryTimeout) throws SQLException {
        this.statement.setQueryTimeout(queryTimeout);
    }

    public final int getQueryTimeout() throws SQLException {
        return this.statement.getQueryTimeout();
    }

    public void setFetchDirection(int fetchDirection) throws SQLException {
        this.statement.setFetchDirection(fetchDirection);
    }

    public final int getFetchDirection() throws SQLException {
        return this.statement.getFetchDirection();
    }

    //
    public void setFetchSize(int fetchSize) throws SQLException {
        this.statement.setFetchSize(fetchSize);
    }

    public final int getFetchSize() throws SQLException {
        return this.statement.getFetchSize();
    }

    //
    public void setMaxRows(int maxRows) throws SQLException {
        this.statement.setMaxRows(maxRows);
    }

    public final int getMaxRows() throws SQLException {
        return this.statement.getMaxRows();
    }

    //
    public void setMaxFieldSize(int maxFieldSize) throws SQLException {
        this.statement.setMaxFieldSize(maxFieldSize);
    }

    public int getMaxFieldSize() throws SQLException {
        return this.statement.getMaxFieldSize();
    }

    public final void cancel() throws SQLException {
        this.statement.cancel();
    }

}
